Skip to content

Fix: allow contained copies within child allocations - #1538

Closed
high-cloud wants to merge 1 commit into
hw-native-sys:mainfrom
high-cloud:agent/copy-to-offset
Closed

Fix: allow contained copies within child allocations#1538
high-cloud wants to merge 1 commit into
hw-native-sys:mainfrom
high-cloud:agent/copy-to-offset

Conversation

@high-cloud

@high-cloud high-cloud commented Jul 27, 2026

Copy link
Copy Markdown

Summary

  • keep the existing Orchestrator.copy_to(worker_id, dst, src, size) API
  • record malloc and CommDomain extents in child-pointer provenance
  • accept copies whose complete destination range is contained by a live allocation or CommDomain window
  • reject wrong-worker, stale, negative-size, and out-of-bounds copies before mailbox/native dispatch
  • retain exact-base requirements for free() and child-memory task dispatch

Why

copy_to() previously validated only an exact registered pointer. A valid chunked copy into a live CommDomain window therefore failed as soon as the destination advanced from window_base to an interior address.

The validation now treats the copy destination as a byte range and proves that the complete range belongs to a live allocation on the selected worker. Exact destinations retain an O(1) lookup; only interior destinations require scanning that worker's live provenance entries. No new public API or caller migration is needed.

Validation

  • python -m pytest -q tests/ut/py/test_worker/test_child_addr_guard.py — 44 passed
  • python -m pytest -q tests/ut — 847 passed, 2 skipped
  • python -m pre_commit run --files python/simpler/orchestrator.py python/simpler/worker.py tests/ut/py/test_worker/test_child_addr_guard.py — passed
  • git diff --check — passed

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cd2fdf8d-081e-4805-944a-272ca37bdd4f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Child-pointer provenance now tracks allocation sizes for mallocs and CommDomain buffers. Orchestrator and L2 copy_to operations validate complete destination ranges, including supported interior pointers. Tests cover bounded copies, aliases, stale pointers, dispatch, and release behavior.

Changes

Child pointer provenance

Layer / File(s) Summary
Allocation extent tracking and role lifetime
python/simpler/worker.py
Provenance entries record malloc and domain byte extents, compute live bounds, and update roles when allocations are cleared or dropped.
Bounded copy integration
python/simpler/orchestrator.py, python/simpler/worker.py
Malloc paths record sizes, while Orchestrator and L2 copy_to paths validate destination ranges before issuing native copies.
Provenance and bounds validation
tests/ut/py/test_worker/test_child_addr_guard.py
Tests update size-aware records and cover interior ranges, out-of-bounds copies, aliases, stale pointers, dispatch, and domain release ordering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

  • hw-native-sys/simpler#1430 — Extends the same child-pointer provenance and guarding paths for wrong-worker and stale-pointer validation.

Poem

I’m a rabbit with bounds in my byte-sized den,
Tracking each pointer from start to its end.
Interior hops pass when the ranges fit,
Overshooting copies now tumble in a pit.
Malloc leaves footprints, domains do too—
Safe little burrows for every queue!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main change: allowing contained copies within child allocations.
Description check ✅ Passed The description is clearly related to the changeset and matches the provenance and range-validation updates.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@high-cloud
high-cloud force-pushed the agent/copy-to-offset branch from 94adb70 to af47001 Compare July 28, 2026 07:41
@high-cloud high-cloud changed the title Add: support offset copies to worker allocations Fix: allow contained copies within child allocations Jul 28, 2026
@high-cloud
high-cloud marked this pull request as ready for review July 28, 2026 07:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/ut/py/test_worker/test_child_addr_guard.py (2)

238-247: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Include a negative-size case in the range rejection matrix.

The provenance contract in python/simpler/worker.py (Lines 5668-5692) rejects negative sizes before native copying, but this parametrization covers only positive overflow and an out-of-range zero-byte destination. Add (0x2000, -1) and retain the no-native-call assertion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ut/py/test_worker/test_child_addr_guard.py` around lines 238 - 247,
Extend the parameterization in test_copy_to_rejects_range_past_allocation to
include (0x2000, -1), and retain or add an assertion that fake.malloc/native
copying is not invoked when the negative size is rejected.

264-265: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert that rejected bounded copies never reach the native backend.

Both tests perform a successful copy first, so failure alone does not prove that the subsequent invalid request was blocked before native dispatch.

  • tests/ut/py/test_worker/test_child_addr_guard.py#L264-L265: assert fake.copy_to.call_count == 1 after the rejected domain-window request.
  • tests/ut/py/test_worker/test_child_addr_guard.py#L459-L460: assert chip.copy_to.call_count == 1 after the rejected L2 request.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ut/py/test_worker/test_child_addr_guard.py` around lines 264 - 265, Add
native-dispatch assertions to both rejected bounded-copy tests: in
tests/ut/py/test_worker/test_child_addr_guard.py lines 264-265, assert
fake.copy_to.call_count == 1 after the invalid domain-window request; at lines
459-460, assert chip.copy_to.call_count == 1 after the invalid L2 request. Keep
the existing successful-copy setup and ValueError assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/simpler/worker.py`:
- Line 463: Sort the entries in the __slots__ tuple alphabetically to satisfy
Ruff RUF023, changing the order of malloc_nbytes and domain_allocation_nbytes
while preserving both slot names.

---

Nitpick comments:
In `@tests/ut/py/test_worker/test_child_addr_guard.py`:
- Around line 238-247: Extend the parameterization in
test_copy_to_rejects_range_past_allocation to include (0x2000, -1), and retain
or add an assertion that fake.malloc/native copying is not invoked when the
negative size is rejected.
- Around line 264-265: Add native-dispatch assertions to both rejected
bounded-copy tests: in tests/ut/py/test_worker/test_child_addr_guard.py lines
264-265, assert fake.copy_to.call_count == 1 after the invalid domain-window
request; at lines 459-460, assert chip.copy_to.call_count == 1 after the invalid
L2 request. Keep the existing successful-copy setup and ValueError assertions
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 87bd3dc4-1b68-45ba-8341-cbfb294840a5

📥 Commits

Reviewing files that changed from the base of the PR and between 723bb14 and af47001.

📒 Files selected for processing (3)
  • python/simpler/orchestrator.py
  • python/simpler/worker.py
  • tests/ut/py/test_worker/test_child_addr_guard.py

Comment thread python/simpler/worker.py Outdated
Track malloc and CommDomain extents in child-pointer provenance. Existing copy_to calls may target a contained interior range while wrong-worker, stale, and out-of-bounds ranges are rejected before the native copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant